#ifndef TCP_SESSION_CONFIG_H
#define TCP_SESSION_CONFIG_H
#include "io_session_config.h"
#include "utils/property/dynamic_property.h"
namespace vpm
{
	namespace mina
	{		
		using namespace vpm::utils;
		class TcpSessionConfig  : public IoSessionConfig 
		{
		public:
			enum TcpMode 
			{
				TCP_ASYNCH, 
				TCP_SYNCH, 
			};

			enum TcpSessionOptions
			{				
				TSO_RECV_BUF_SIZE,
				TSO_SEND_BUF_SIZE,
				TSO_TCP_SOLINGER,
				TSO_TCP_NODELAY,
				TSO_TCP_MODE,
			};

			TcpSessionConfig()
			{
				m_tcpSessionOptions.set_property(TSO_RECV_BUF_SIZE,0);// 0 will use the  tcp default value
				m_tcpSessionOptions.set_property(TSO_SEND_BUF_SIZE,0);
				m_tcpSessionOptions.set_property(TSO_TCP_SOLINGER,false);	
				m_tcpSessionOptions.set_property(TSO_TCP_NODELAY,false);
				m_tcpSessionOptions.set_property(TSO_TCP_MODE,TCP_ASYNCH);
			}

            TcpSessionConfig(TcpSessionConfig & other)
            {
                m_tcpSessionOptions = other.m_tcpSessionOptions; 
            }

			int get_receive_buffer_size()
			{
				return m_tcpSessionOptions.get_property<int>(TSO_RECV_BUF_SIZE);
			}

			void set_receive_buffer_size(int bufsize)
			{
				m_tcpSessionOptions.set_property(TSO_RECV_BUF_SIZE,bufsize);
			}

			int get_send_buffer_size()
			{				
				return m_tcpSessionOptions.get_property<int>(TSO_SEND_BUF_SIZE);
			}

			void set_send_buffer_size(int bufsize)
			{
				m_tcpSessionOptions.set_property(TSO_SEND_BUF_SIZE,bufsize);
			}

			bool get_so_linger()
			{
				return m_tcpSessionOptions.get_property<bool>(TSO_TCP_SOLINGER);
			}

			void set_so_linger(bool flag)
			{
				m_tcpSessionOptions.set_property(TSO_TCP_SOLINGER,flag);				
			}

			bool get_tcp_nodelay()
			{
				return m_tcpSessionOptions.get_property<bool>(TSO_TCP_NODELAY);
			}

			void set_tcp_nodelay(bool flag)
			{				
				m_tcpSessionOptions.set_property(TSO_TCP_NODELAY,flag);
			}

			void set_tcp_mode(TcpMode mode)
			{				
				m_tcpSessionOptions.set_property(TSO_TCP_MODE,mode);
			}

			TcpMode get_tcp_mode()
			{
				return m_tcpSessionOptions.get_property<TcpMode>(TSO_TCP_MODE);				
			}
			
		private:		
			DynamicProperty<int> m_tcpSessionOptions;
		};
	}
}

#endif // TCP_SESSION_CONFIG_H


